package com.aiju.cash.core.api;

import com.aiju.app.callback.HttpCallback;
import com.aiju.common.http.interceptor.HttpFactory;
import com.aiju.widgit.dialog.DialogHelper;

import java.util.HashMap;
import java.util.Map;

import static com.aiju.app.config.ConfigManager.INIT_SERVER_HOST;

/**
 * 多店铺api
 * Created by Administrator on 2017/6/13.
 *
 * @author 流冥
 */

public class ShopManagetApi extends BaseApi {

    private String shopList = INIT_SERVER_HOST + "/shop/shopList"; //门店列表
    private String switchList = INIT_SERVER_HOST + "/shop/switchList"; //切换店铺列表
    private String saveShop = INIT_SERVER_HOST + "/shop/saveShop"; //添加门店
    private String update = INIT_SERVER_HOST + "/shop/update"; //店铺更新接口
    private String updateShopGoodsAuth = INIT_SERVER_HOST + "/shop/updateShopGoodsAuth"; //店铺权限配置接口

    private String clerkList = INIT_SERVER_HOST + "/user/clerkList"; //店员列表接口
    private String addClerk = INIT_SERVER_HOST + "/user/addClerk"; //添加店员接口
    private String deleteClerk = INIT_SERVER_HOST + "/user/deleteClerk"; //删除店员接口
    private String updateClerk = INIT_SERVER_HOST + "/user/updateClerk"; //更改店员信息接口
    private String inviteByNote = INIT_SERVER_HOST + "/user/inviteByNote"; //短信邀请成为店员接口

    private String getRelationParentGoodsList = INIT_SERVER_HOST + "/goodsType/getRelationParentGoodsList"; //关联商品列表
    private String saveOrDeleteRelationGoods = INIT_SERVER_HOST + "/goodsType/saveOrDeleteRelationGoods"; //关联主店商品-添加或取消关联商品 接口

    private String grantERP = INIT_SERVER_HOST + "/user/grantERP";//对用户进行授权操作 这是 移动端 进行的请求的操作
    private String getGrantStatus = INIT_SERVER_HOST + "/user/getGrantStatus";//获取授权的状态

    private HttpFactory instance;

    public ShopManagetApi(DialogHelper dialogHelper) {
        super(dialogHelper);
        instance = HttpFactory.getInstance();
        instance.setDialogHelper(dialogHelper);
    }


    public void setDialogHelper(DialogHelper dialogHelper) {
        instance.setDialogHelper(dialogHelper);
    }

    /**
     * 获取门店列表
     */
    public void getShopList(int currentNum, int pageSize, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("storeId", mUser.getParentStoreId());
        map.put("role", mUser.getRole());
/*        map.put("operatorId", mUser.getOperatorId());
        map.put("currentNum", String.valueOf(currentNum));
        map.put("pageSize", String.valueOf(pageSize));*/
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(shopList, map, callback);
    }

    /**
     * 获取切换店铺列表
     */
    public void getSwitchList(int currentNum, int pageSize, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("storeId", mUser.getParentStoreId());
        map.put("role", mUser.getRole());
/*        map.put("operatorId", mUser.getOperatorId());
        map.put("currentNum", String.valueOf(currentNum));
        map.put("pageSize", String.valueOf(pageSize));*/
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(switchList, map, callback);
    }

    /**
     * 店员列表接口
     */
    public void clerkList(String storeId, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("storeId", storeId);
        map.put("role", mUser.getRole());
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(clerkList, map, callback);
    }

    /**
     * 添加店员接口
     */
    public void addClerk(String storeId, String shopId, String shopName, String parentStoreId, String role, String userName, String phone,
                         String creator, String creatorPhone, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("storeId", storeId);
        map.put("shopId", shopId);
        map.put("shopName", shopName);
        map.put("parentStoreId", parentStoreId);
        map.put("role", role);
        map.put("userName", userName);
        map.put("phone", phone);
        map.put("fromPhone", creatorPhone);
        map.put("creator", creator);
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(addClerk, map, callback);
    }

    /**
     * 删除店员接口
     */
    public void deleteClerk(String id, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("id", id);
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(deleteClerk, map, callback);
    }

    /**
     * 更改店员信息接口
     */
    public void updateClerk(String storeId, String id, String userName, String role, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("storeId", storeId);
        map.put("id", id);
        map.put("userName", userName);
        map.put("role", role);
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(updateClerk, map, callback);
    }

    /**
     * 短信邀请成为店员接口
     */
    public void inviteByNote(String storeId, String shopName, String fromPhone, String toPhone, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("storeId", storeId);
        map.put("shopName", shopName);
        map.put("fromPhone", fromPhone);
        map.put("toPhone", toPhone);
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(inviteByNote, map, callback);
    }

    /**
     * 店铺添加接口
     */
    public void saveShop(String shopName, String provinceCode,
                         String cityCode, String districtCode, String addressDetail, String codeName,
                         String longitude, String latitude, String contactNumber, String shopType, HttpCallback callback) {

        Map<String, String> map = new HashMap<>();
        map.put("storeId", mUser.getStoreId());
        map.put("shopName", shopName);
        map.put("isDiscount", "");
        map.put("parentStoreId", mUser.getParentStoreId());
        map.put("provinceCode", provinceCode);
        map.put("cityCode", cityCode);
        map.put("districtCode", districtCode);
        map.put("codeName", codeName);
        map.put("addressDetail", addressDetail);
        map.put("longitude", longitude);
        map.put("latitude", latitude);
        map.put("contactNumber", contactNumber);
        map.put("shopType", shopType);
        instance.makeProxy().requestPost(saveShop, map, callback);
    }

    /**
     * 店铺更新接口
     */
    public void updateShop(String id, String shopName, String provinceCode,
                           String cityCode, String districtCode, String addressDetail, String codeName,
                           String longitude, String latitude, String contactNumber, String shopType, HttpCallback callback) {

        Map<String, String> map = new HashMap<>();
        map.put("id", id);
        map.put("shopName", shopName);
        map.put("isDiscount", "");
        map.put("parentStoreId", mUser.getParentStoreId());
        map.put("provinceCode", provinceCode);
        map.put("cityCode", cityCode);
        map.put("districtCode", districtCode);
        map.put("codeName", codeName);
        map.put("addressDetail", addressDetail);
        map.put("longitude", longitude);
        map.put("latitude", latitude);
        map.put("contactNumber", contactNumber);
        map.put("shopType", shopType);
        instance.makeProxy().requestPost(update, map, callback);
    }

    /**
     * 关联主店商品- 显示列表接口
     */
    public void getRelationParentGoodsList(String storeId, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("token", mUser.getToken());
        map.put("storeId", storeId);
        map.put("parentStoreId", mUser.getParentStoreId());
        instance.makeProxy().requestPost(getRelationParentGoodsList, map, callback);
    }

    /**
     * 关联主店商品-添加或取消关联商品 接口
     */
    public void saveOrDeleteRelationGoods(String storeId, String saveGoodsIds, String deleteGoodsIds, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("storeId", storeId);
        map.put("saveGoodsIds", saveGoodsIds);
        map.put("deleteGoodsIds", deleteGoodsIds);
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(saveOrDeleteRelationGoods, map, callback);
    }

    /**
     * 店铺权限配置接口
     */
    public void updateShopGoodsAuth(String storeId, String modifyRelationGoods, String deleteRelationGoods, String manageOwnGoods, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("storeId", storeId);
        map.put("modifyRelationGoods", modifyRelationGoods);
        map.put("deleteRelationGoods", deleteRelationGoods);
        map.put("manageOwnGoods", manageOwnGoods);
        instance.makeProxy().requestPost(updateShopGoodsAuth, map, callback);
    }

    /**
     * 对用户进行授权操作 这是 移动端 进行的请求的操作
     * token	是	string	令牌
     * rId	是	string	由ERP系统生成的标志
     * pStoreId	是	String	总店铺
     * storeIds	是	string	需要授权的店铺的ID ， 多个店铺使用逗号（英文的逗号）隔开
     */
    public void getGrant(String rId, String pStoreId, String storeIds, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("rId", rId);
        map.put("pStoreId", pStoreId);
        map.put("storeIds", storeIds);
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(grantERP, map, callback);
    }

    /**
     * 获取授权的状态
     * 这是 移动端 进行的请求的操作
     * ERP系统每隔三秒会请求一次，如果ERP 系统获取了授权。 授权成功，如果没有，授权失败；
     */
    public void getGrantStatus(String rId, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("rId", rId);
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(getGrantStatus, map, callback);
    }

}
